﻿using System.Windows;
using System.Windows.Input;
using Greenshot2Core.WPF.Command;
using Greenshot2.About;
using Greenshot2.Settings;
using Greenshot2Editor.Editor;
using Greenshot2Core.Interfaces;
using Greenshot2Core.Capture;
using Greenshot2.Capture;
using System;
using System.Windows.Media.Imaging;

namespace Greenshot2.ContextMenu {
	/// <summary>
	/// Container for the commands that are used in the context menu
	/// </summary>
	public class ContextMenuCommands {
		private static NLog.Logger LOG = NLog.LogManager.GetCurrentClassLogger();

		public ContextMenuCommands() {
			LOG.Debug("Creating ContextMenuCommands");
			CaptureRegionCommand = new RelayCommand(param => {
				CaptureContainer capture = new CaptureContainer();
				Int32Rect captureRect = new Int32Rect((int)SystemParameters.VirtualScreenLeft, (int)SystemParameters.VirtualScreenTop, (int)SystemParameters.VirtualScreenWidth, (int)SystemParameters.VirtualScreenHeight);
				capture.Image = CaptureScreen.CaptureRectangle(captureRect);
				CaptureWindow captureWindow = new CaptureWindow(capture);
				Nullable<bool> dialogResult = captureWindow.ShowDialog();
				if (dialogResult.HasValue && dialogResult.Value) {
					// Crop here
					capture.Image = new CroppedBitmap(capture.Image, captureWindow.Selection);
					new EditorWindow(capture).Show();
				}
			}, param => true);
			CaptureLastRegionCommand = new RelayCommand(param => {
			}, param => false);
			CaptureWindowCommand = new RelayCommand(param => {
			}, param => false);
			CaptureFullscreenCommand = new RelayCommand(param => {
				CaptureContainer capture = new CaptureContainer();
				Int32Rect captureRect = new Int32Rect((int)SystemParameters.VirtualScreenLeft, (int)SystemParameters.VirtualScreenTop, (int)SystemParameters.VirtualScreenWidth, (int)SystemParameters.VirtualScreenHeight);
				capture.Image = CaptureScreen.CaptureRectangle(captureRect);
				new EditorWindow(capture).Show();
			}, param => true);
			CaptureIECommand = new RelayCommand(param => {
			}, param => false);
			CaptureWindowFromListCommand = new RelayCommand(param => {
			}, param => false);
			CaptureIEFromListCommand = new RelayCommand(param => {
			}, param => false);
			OpenImageFromClipboardCommand = new RelayCommand(param => {
			}, param => false);
			OpenImageFromFileCommand = new RelayCommand(param => {
			}, param => false);
			OpenSettingsCommand = new RelayCommand(param => new SettingsWindow().Show());
			AboutCommand = new RelayCommand(param => new AboutWindow().Show());
			ExitCommand = new RelayCommand(param => Application.Current.Shutdown());
		}

		public ICommand CaptureRegionCommand {
			get;
			internal set;
		}

		public ICommand CaptureLastRegionCommand {
			get;
			internal set;
		}

		public ICommand CaptureWindowCommand {
			get;
			internal set;
		}

		public ICommand CaptureFullscreenCommand {
			get;
			internal set;
		}

		public ICommand CaptureIECommand {
			get;
			internal set;
		}

		public ICommand CaptureWindowFromListCommand {
			get;
			internal set;
		}

		public ICommand CaptureIEFromListCommand {
			get;
			internal set;
		}

		public ICommand OpenImageFromClipboardCommand {
			get;
			internal set;
		}

		public ICommand OpenImageFromFileCommand {
			get;
			internal set;
		}

		public ICommand OpenSettingsCommand {
			get;
			internal set;
		}

		public ICommand AboutCommand {
			get;
			internal set;
		}

		public ICommand ExitCommand {
			get;
			internal set;
		}

	}
}
